import matplotlib.pyplot as plt
import scipy.io.wavfile as wave
import scipy.signal as signal
import numpy as np
import struct

# 首先要将文件保存为16位精度的wav文件
# 读取wav文件
sampleFreq, snd = wave.read(input('Enter a wav filename:'))
# 变为无符号数
snd = snd + 32767
# 重采样
snd = signal.resample(snd, int(len(snd) * 30000 / sampleFreq))
snd = snd.astype('uint16')
# 保存
f = open(input('Enter wav filename to save:'), 'wb')
for i in range(len(snd)):
    f.write(struct.pack('H', snd[i]))
f.close()
